package ooday04;

import ooday04.Animal;
import ooday04.Chick;
import ooday04.Dog;

public class Test {
    public static void main(String[] args) {
        //Animal o = new Animal(); //抽象类不能被实例化
        Animal[] animals = new Animal[5]; //创建Animal数组对象
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 2, "黑");
        animals[2] = new Dog("小金", 2, "黑");
        animals[3] = new Dog("小花", 2, "黑");
        animals[4] = new Dog("小灰", 2, "黑");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();

        }


        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("小白", 1, "白");
        dogs[2] = new Dog("小辉", 3, "棕");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++) { //遍历数组
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks = new Chick[1];
        chicks[0] = new Chick("小花", 22, "黄色");
        System.out.println(chicks[0].name);
        chicks[0].age = 45;
        for (int i = 0; i < chicks.length; i++) { //遍历数组
            System.out.println(chicks[i].name); //输出每个动物的名字
            animals[i].eat();
            if (animals[i] instanceof Chick) {
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Fish) {
                Fish fish = (Fish) animals[i];
                fish.swim();

            }
            if (animals[i] instanceof Dog) {
                Dog dog = (Dog) animals[i];
                dog.lookHome();


            }
        }
    }
}